﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ProductLabelCommand;
using MediatR;
using SqlSugar;
using System.Reflection;

namespace J.ProductSet.Application.CommandHandler.ProductLabelCommandHandler
{
    public class ProductLabelPOSTCommandHandler : IRequestHandler<ProductLabelPOSTCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ProductLabelPOSTCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(ProductLabelPOSTCommand request, CancellationToken cancellationToken)
        {
            ProductLabel models = _mapper.Map<ProductLabel>(request);
            return await _sqlSugarClient.Insertable(models).ExecuteCommandAsync();
        }
    }
}
